package com.gelpag.base.tools;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import tools.utils.Common;

import javax.annotation.PostConstruct;

@Component
public class ParamCacheUtil {

    @Autowired
    StringRedisTemplate stringRedisTemplate;
    static StringRedisTemplate staticRedisTemplate;

    //在容器启动的时候加载这个方法，目的是给staticRedis赋值
    @PostConstruct
    public void init() {
        staticRedisTemplate = stringRedisTemplate;
    }

    /**
     * 通过参数名获取Redis中的值
     * @param params_type
     * @return
     */
    public static String getParamValue(String params_type) {

        return Common.isNullString(params_type) ? "" : staticRedisTemplate.opsForValue().get(params_type);
    }
}
